<template>
  <div id="setlog" class="setlog">
<!--    <div class="header_text">华北能源监管局公共服务平台账号更改</div>-->
<!--    <div style="margin-bottom: 16px" class="LogHeader">-->
<!--      <div class="logbox">-->
<!--        <div class="input_log">-->
<!--          <a-input addon-before="用户名" class="input input1" v-model="userlist.username" />-->

<!--          <a-input addon-before="密码" class="input input_2" v-model="userlist.password" />-->

<!--          <a-input addon-before="间隔时间" class="input input_3" v-model="userlist.intervalTime" />-->
<!--          <a-button type="primary" class="button button0" icon="check-circle" @click="editSetLog">修改</a-button>-->
<!--        </div>-->
<!--      </div>-->
<!--    </div>-->
    <div class="set_text">
      <div class="set_info">采集日志</div>
      <div class="set_button">
        <a-button type="primary" class="button button1" icon="reload" @click="reload">刷新</a-button>
        <a-button type="primary" class="button button2" icon="close-circle" @click="close">清除</a-button>
      </div>
    </div>
    <div class="table">
      <a-table :columns="columns" :data-source="data" bordered :rowKey="data.key">
        <template slot="name" slot-scope="text">
          <a>{{ text }}</a>
        </template>
      </a-table>
    </div>
  </div>
</template>

<script>
import { getAction, postAction, putAction, deleteAction } from '@/api/manage'

const columns = [
  {
    title: '时间',
    dataIndex: 'date',
    width: 180
  },
  {
    title: '类型',
    dataIndex: 'type',
    width: 80
  },
  {
    title: '采集端',
    dataIndex: 'collectTerminal',
    width: 130
  },
  {
    title: '流程点',
    dataIndex: 'processPoint',
    width: 130
  },
  {
    title: '日志信息',
    dataIndex: 'message',
    ellipsis: true
  }
]

export default {
  data() {
    return {
      data: [],
      columns,
      userlist: {}
    }
  },
  created() {
    this.postList()
  },
  methods: {
    // 请求log日志列表及用户信息
    postList() {
      var register = {}
      getAction('/nlpcs/nlpcs_12398Log/list', register)
        .then(res => {
          this.data = res.result
          // this.data = res.result.records

          // this.data.forEach((item, index) => {
          //   item.key = index + 1
          // })
        })
        .catch(err => {
          console.log(err)
        })

      getAction('/nlpcs/nlpcsSetup/list', register)
        .then(res => {
          console.log(res.result.records[0]);

          // this.userlist = res.result
          this.userlist = res.result.records[0]
        })
        .catch(err => {
          console.log(err)
        })
    },

    // 刷新按钮点击事件
    reload() {
      this.postList()
      this.$message.info('刷新成功')
    },

    // 清除按钮点击事件
    close() {
      var s = {}
      deleteAction('/nlpcs/nlpcs_12398Log/deleteBatch', s)
        .then(res => {
          this.$message.info('清除成功')
          this.postList()
          console.log(res)
        })
        .catch(err => {
          console.log(err)
        })
    },

    // 修改账号密码
    editSetLog() {
      console.log(this.userlist)
      // var register = this.userlist
      // console.log(register);

      putAction('/nlpcs/nlpcsSetup/edit', this.userlist)
        .then(res => {
          this.$message.info('修改成功')
          this.postList()
          console.log(res)
        })
        .catch(err => {
          console.log(err)
        })
    }
  }
}
</script>

<style>
.setlog {
  margin: 40px;
  min-height: calc(100vh - 59px);
}
.table {
  margin-top: 30px;
}

.input:hover {
  box-shadow: 0px 0px 4px #87cefa;
}

.header_text {
  font-size: 30px;
  font-weight: 600;
  margin-bottom: 30px;
}

.logbox {
  display: flex;
  justify-content: space-between;
}

.input {
  width: 150px;
  margin-right: 10px;
}

.input1 {
  width: 300px;
}
.button {
  margin-left: 10px;
}

.set_info {
  font-size: 30px;
  font-weight: 600;
}
.set_text {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 10px;
}
</style>
